package com.trg.designmodel.decorator;

/**
 * @ClassName: Decorator
 * @Description:    装饰者
 * @Author: tangrg
 * @Date: 2021/7/6 16:03
 * @Version: 1.0
 * @Return:
 **/
public class Decorator extends Drink {

    private volatile Drink drink;

    public Decorator(Drink drink) {
        this.drink = drink;
    }

    @Override
    public float cost() {
        //这里对具体coffee的价格和配料的价格相加
//        System.out.println("super.getPrice():"+super.getPrice());
//        System.out.println("drink.cost()："+drink.cost());
        return super.getPrice() + drink.cost();
    }

    @Override
    public String getDesc() {
        //对装饰者的信息进行重写
        return super.getDesc() + " " + getPrice() + " && " + drink.getDesc();
    }
}
